// interface Func {
//   (x: number, y: number): void
// }

// const add: Func = function (x, y): void {
//   console.log(x, y)
// }

// const add1: Func = (x, y) => {}

;(() => {
  let add: (x: number, y: number) => number

  add = (q: number, w: number): number => q + w

  // interface Add {
  //   (x: number, y: number): number
  // }

  type Add = (x: number, y: number) => number

  type isString = string

  // let addFunc: Add
  // addFunc = (q: number, w: number): number => q + w

  // let addFunc
  // addFunc = (arg1, arg2, arg3) => arg1 + arg2 + (arg3 ? arg3 : 0)
  type AddFunction = (arg1: number, arg2: number, arg3?: number) => number

  // const addFunction: AddFunction = (x: number, y: number, z?: number) => {
  //   return x + y + (z ? z : 0)
  // }
  const addfunction = (x: number, y: number) => x + y
  console.log(addfunction(1, 2))

  const add1 = (x: number, y: number = 100) => x + y
  // console.log(add1(1, '2'))

  // Array.prototype.slice.apply() 将类数组转成真正的数组
  const handleData = (x: number, y: number, ...arg: number[]): void => {
    console.log(x, y, arg)
  }

  handleData(1, 2, 34, 5, 321, 3, 123, 12)

  // 函数重载

  function handledata(x: string): string[]
  function handledata(y: number): number[]
  function handledata(x: any): any {
    if (typeof x === 'string') {
      return x.split('')
    } else if (typeof x === 'number') {
      return x
        .toString()
        .split('')
        .map(item => Number(item))
    } else {
      return x
    }
  }

  console.log(handledata(23123123))

  interface IHandle<T> {
    (x: T): T[]
  }

  const getArr: IHandle<string> = (x: string) => {
    return x.split('')
  }
})()
